package com.renfei.medialibrary.util;

import android.media.MediaCodecList;

import java.util.HashMap;
import java.util.Map;

public class VideoSupportUtil {
    private static Map<String, String> codecMap = new HashMap<>();

    static {
        codecMap.put("h264", "video/avc");
    }

    public static String findVideoCodecName(String ffcodecName) {
        if (codecMap.containsKey(ffcodecName)) {
            return codecMap.get(ffcodecName);
        }
        return "";
    }

    public static boolean isLocalSupportCodec(String ffcodecName) {
        boolean isSupportVideo = false;
        int count = MediaCodecList.getCodecCount();

        for (int i = 0; i < count; i++) {
            String[] types = MediaCodecList.getCodecInfoAt(i).getSupportedTypes();

            for (int j = 0; j < types.length; j++) {

                if (types[j].equals(findVideoCodecName(ffcodecName))) {
                    isSupportVideo = true;
                    break;
                }
                if (isSupportVideo) {
                    break;
                }
            }
        }
        return isSupportVideo;
    }
}
